<%@page import="java.util.Locale"%>
<%@page import="com.skali.portlet.governmentSpending.service.service.SpendingTypeLocalServiceUtil"%>
<%@page import="com.skali.portlet.governmentSpending.service.model.SpendingType"%>
<%@ include file="/html/portlet/governmentspending/init.jsp" %>
<%

int typeCount = SpendingTypeLocalServiceUtil.getSpendingTypesCount(); 

List<SpendingType> spendingType = SpendingTypeLocalServiceUtil.getSpendingTypes(0,typeCount );


PortletURL editURL = renderResponse.createRenderURL();
editURL.setParameter("jspPage","/html/portlet/governmentspending/admin/edit-spendingtype.jsp");
%>

<aui:layout>
	<aui:column columnWidth="85" first="true">
	  <table border="1" width="90%">
	  	<tr>
	  	  <th>Spending Type</th>
	  	  <th>Description</th>
	  	  <th>Action</th>
	  	</tr>
	  	
	  <%
	   	for(SpendingType spendType : spendingType){
	    boolean isEditable = false;
	    String typeName = spendType.getSpendingName(themeDisplay.getLocale());
	   	editURL.setParameter("spendingTypeId",String.valueOf(spendType.getSpendingId()));
	   	if(typeName.equalsIgnoreCase("Contracts") || typeName.equalsIgnoreCase("Others")) isEditable = true;
	  %><tr>
	  		<td><%=typeName%></td>
	  		<td><%=spendType.getDescription(themeDisplay.getLocale()) %></td>
	  		
	  		<c:if test="<%=(!(isEditable) && spendingType.size()>0)%>">
	  			<td><a href="<%=editURL.toString()%>">Edit</a></td>
	  		</c:if>
	  		<c:if test="<%=(spendType.getCustomField()&& spendingType.size()>0 && !isEditable) %>">
	  		<portlet:actionURL name="spendingType" var="delSpendType">
	  		 <portlet:param name="edit" value="<%=String.valueOf(spendType.getSpendingId()) %>"></portlet:param>
	  		 <portlet:param name="spendingDelete" value="true"></portlet:param>
	  		</portlet:actionURL>
		  		<td><a href="javascript:void(0)" onclick="delSpendType('<%=delSpendType.toString()%>');">Delete</a></td>
	  		</c:if>
	  	 </tr>
	  <%	   	
	   		
	   	}
	  %>
	 
	  </table>
	</aui:column>
	<aui:column columnxmlns="15" last="true">
		<c:if test="<%=(typeCount<=7)%>">
		<%editURL.setParameter("addType","true");%>
		     <aui:button-row>
		     	<aui:button type="button" name="addSpendType" value="Add Spending Type" onClick="<%=editURL.toString()%>"></aui:button>
		     </aui:button-row>
		</c:if>
	</aui:column>

</aui:layout>
<aui:script>
function delSpendType(url){

var r=confirm("Do you want to delete the Spending Type!");
if (r==true)
  {
  window.location.href=url;
  }
else
  {
  return false;
  }
}

</aui:script>